using System.IO;
using System.Xml.Serialization;

namespace SolarWinds
{
    public class Settings
    {
        #region General App Settings

        /// <summary>
        /// The path to look for all media in
        /// </summary>
        public string MediaPath = @"";

        /// <summary>
        /// The name of the window when running in windowed mode
        /// </summary>
        public string WindowTitle = "DeepSpace";

        public int ScreenWidth = 800;

        public int ScreenHeight = 600;

        public bool FullScreen = false;

        public bool VerticalSync = false;

        #endregion

        #region Load/Save code
        /// <summary>
        /// Saves the current settings
        /// </summary>
        /// <param name="filename">The filename to save to</param>
        public void Save(string filename)
        {
            Stream stream = File.Create(filename);

            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            serializer.Serialize(stream, this);
            stream.Close();
        }

        /// <summary>
        /// Loads settings from a file
        /// </summary>
        /// <param name="filename">The filename to load</param>
        public static Settings Load(string filename)
        {
            Stream stream = File.OpenRead(filename);
            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            
            Settings res = (Settings)serializer.Deserialize(stream);

            stream.Close();

            return res;
        }
        #endregion
    }
}